﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;
namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllVendorBillsByVIDDataAction : BestLifeDataAction<List<Vendor_Bill>>
    {

        private string GvSupId;
        public BestLifeGetAllVendorBillsByVIDDataAction(string PSupId)
        {
            GvSupId = PSupId;
        }

        public override List<Vendor_Bill> Body(SqlConnection PConn)
        {
            try
            {
                List<Vendor_Bill> LvList = new List<Vendor_Bill>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetVendorBillsById";
                LvCommand.Parameters.Add(new SqlParameter("@SupID", GvSupId));//when passing parameters to the SP

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Vendor_Bill LvVendorBills = new Vendor_Bill();
                    LvVendorBills.SB_No = LvReader.GetValue(0).ToString();
                    LvVendorBills.Ven_No = LvReader.GetValue(1).ToString();
                    LvVendorBills.Ven_date = DateTime.Parse(LvReader.GetValue(2).ToString());
                    LvVendorBills.Total = decimal.Parse(LvReader.GetValue(3).ToString());
                    LvVendorBills.Po_Id = LvReader.GetValue(4).ToString();
                    LvVendorBills.User_Id = LvReader.GetValue(5).ToString();
                    LvVendorBills.Date_Create = DateTime.Parse(LvReader.GetValue(6).ToString());
                    LvList.Add(LvVendorBills);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
